package com.cdream.basic.algorithm.leetcode.map;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author cdream
 * @date 10/8/21
 */
public class Question187 {
    public List<String> findRepeatedDnaSequences(String s) {
        int l = s.length();
        Map<String,Integer> map = new HashMap<String,Integer>();
        for(int i = 0; i<=l - 10; i++) {
            String subString = s.substring(i,i+10);
            map.put(subString,map.getOrDefault(subString,0)+1);
        }
        List<String> res = new ArrayList<String>();
        map.forEach((k,v)->{
            if (v>1){
                res.add(k);
            }
        });
        return res;
    }
}
